package com.zz.common.handle;

import com.zz.common.protocol.ProtocolFactory;
import com.zz.common.protocol.TunnelProtocol;
import com.zz.common.protocol.handle.ProtocolHandle;
import io.netty.buffer.ByteBuf;
import io.netty.channel.ChannelHandlerContext;
import io.netty.handler.codec.MessageToByteEncoder;
import lombok.extern.slf4j.Slf4j;

/**
 * 消息编码处理器
 *
 * @author zz
 */
@Slf4j
public class TunnelProtocolEncode extends MessageToByteEncoder<TunnelProtocol> {
    @Override
    protected void encode(ChannelHandlerContext context, TunnelProtocol protocol, ByteBuf byteBuf) throws Exception {
        try {
            ProtocolHandle protocolHandle = ProtocolFactory.getProtocolHandle();
            protocolHandle.encode(context, protocol, byteBuf);
        } catch (Exception e) {
            log.info("消息协议编码失败！error:【{}】", e.getMessage());
        }

    }
}
